package emby.stmt;

import emby.EmbyRuntime;
import emby.expr.Variable;
import emby.lang.Block;
import emby.lang.EmbyFunction;
import emby.lang.Scope;
import emby.writer.IEmbyCodifier;

public class DefineFunction extends Statement {

	private static final long serialVersionUID = 2826525502860307659L;
	String name;
	Block body;
	Variable[] params;

	public DefineFunction(String fname, Block _body, Variable... parameters){
		name = fname;
		body = _body;
		params = parameters;
		_body.add(Return.retNull);
	}

	@Override
	public Object eval(Scope s) {
		EmbyFunction func =  new EmbyFunction(name, s, body, params );
		if(EmbyRuntime.echo){
			emby.util.Print.println("Defining function "+func);
		}
		s.setVar(name, func);
		return null;
	}
	
	public void codify(IEmbyCodifier ec){
		ec.fndef(name, body, params);
	}
}
